package com.atelier.plugin.database.ui;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class ZoomableTextField extends JPanel {
    private JTextField textField;
    private JButton zoomInButton;
    private JButton zoomOutButton;

    public ZoomableTextField() {
        setLayout(new BorderLayout());

        // 创建文本输入框
        textField = new JTextField();
        add(textField, BorderLayout.CENTER);

        // 创建放大按钮
        zoomInButton = new JButton("+");
        zoomInButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                // 放大文本框
                Dimension currentSize = textField.getSize();
                Dimension newSize = new Dimension((int) (currentSize.getWidth() * 1.2), (int) (currentSize.getHeight() * 1.2));
                textField.setPreferredSize(newSize);
                textField.revalidate(); // 重新布局组件
            }
        });

        // 创建缩小按钮
        zoomOutButton = new JButton("-");
        zoomOutButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                // 缩小文本框
                Dimension currentSize = textField.getSize();
                Dimension newSize = new Dimension((int) (currentSize.getWidth() * 0.8), (int) (currentSize.getHeight() * 0.8));
                textField.setPreferredSize(newSize);
                textField.revalidate(); // 重新布局组件
            }
        });

        // 添加放大和缩小按钮到面板
        JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
        buttonPanel.add(zoomInButton);
        buttonPanel.add(zoomOutButton);
        add(buttonPanel, BorderLayout.EAST);
    }

    // 获取文本框的文本
    public String getText() {
        return textField.getText();
    }

    // 设置文本框的文本
    public void setText(String text) {
        textField.setText(text);
    }


}
